package cn.quevo.core.util;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import cn.quevo.core.lang.StringUtils;

/**
 * 行转列
 *
 * @author July july_sky@foxmail.com
 * @date 2018-03-09 13:33:09
 * @Copyright ©2015-2035 湘豫(北京)科技有限公司. All Rights Reserved.
 * @version 1.0
 * @param null
 * @return
 */
public class RecordMap {
	
	/**
	 * 类型转换
	 * 
	 * @param results
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static Map<String,Object> convertRecordMap(List<Map> results){
		return convertRecordMap(results,"key");
	}
	/**
	 * 类型转换
	 * 
	 * @param results
	 * @param key
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static Map<String,Object> convertRecordMap(List<Map> results,String key){
		if(StringUtils.isBlank(results)){
			return null;
		}
		Map<String,Object> recordMap = new LinkedHashMap<>();
		Map<String,Object> customs = new HashMap<>();
		for(Map map : results){
			if(StringUtils.isBlank(map.get(key))){
				continue;
			}
			for(Object mapKey : map.keySet()){
				if(!StringUtils.isBlank(mapKey)){
					customs.put(mapKey.toString().trim(), map.get(mapKey));
				}
			}
			recordMap.put(map.get(key).toString().trim(), customs);
		}
		return recordMap;
	}
}
